// 基于提供的`info.json`依次实现如下功能,
const fs = require("fs");
const path = require("path");
// 1. 读取`info.json`并转为**数组**
const data = JSON.parse(
  fs.readFileSync(path.join(__dirname, "info.json"), "utf8")
);
//计数器
let i = 0;
let countID = setInterval(() => {
  i++;
  let num = Math.floor(Math.random() * data.length);
  // 2. 随机从**数组**中获取一条数据
  const res = data[num];
  // 3. 累加`count`的值
  res.count++;
  console.log(res);
  console.log(res.count);
  // 4. 重新保存回`info.json`(**覆盖**)

  fs.writeFileSync(
    path.join(__dirname, "info.json"),
    JSON.stringify(data),
    "utf8"
  );

  if (i === 10) {
    clearInterval(countID);
  }
}, 1000);
